package com.ryan.spring.annotation.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by kaimin on 31/1/2019.
 * time : 14:08
 */
public class FailFast {

    private static List<String> list=new ArrayList<>();

    public static void main(String[] args) {

        new threadOne().start();
        new threadTwo().start();
    }

    private static void  printAll(){
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next()+",");
        }
    }

    /**
     * 向其中加入数据
     */
    private static class threadOne extends Thread{
        @Override
        public void run() {
            int i=0;
            while (i < 6) {
                list.add(String.valueOf(i));
                printAll();
                i++;
            }
        }
    }

    private static class threadTwo extends Thread{
        @Override
        public void run() {
            int i=10;
            while (i < 16) {
                list.add(String.valueOf(i));
                printAll();
                i++;
            }
        }
    }




}
